﻿using UnityEngine;

namespace Core
{
    public class SceneItem : Entity, IAwake<Transform, int, float>, IUpdate
    {
        private float time;
        private int count;
        private Vector3 position;
        private Transform transform;

        public Vector3 Position
        {
            get => position;
            set
            {
                if(transform != null)
                    transform.position = value;
                position = value;
            }
        }

        void IAwake<Transform, int, float>.Awake(Transform transform, int count, float time)
        {
            this.count = count;
            this.transform = transform;
            this.time = time;
        }

        void IUpdate.Update()
        {
            time -= Time.deltaTime;
            if (time < 0)
            {
                this.Dispose();
            }
        }

        public override void Dispose()
        {
            base.Dispose();
            if (transform != null)
            {
                GameObject.Destroy(transform.gameObject);
                transform = null;
            }
        }
    }
}
